package com.hjm.project.agentInfo.distributionAdjust.controller;

import com.hjm.common.utils.DateUtils;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.framework.web.page.TableDataInfo;
import com.hjm.project.agentInfo.distributionAdjust.domain.DistributionAdjust;
import com.hjm.project.agentInfo.distributionAdjust.service.IDistributionAdjustService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 服务商分润调整项Controller
 * 
 * @author generator
 * @date 2020-11-27
 */
@Controller
@RequestMapping("/agentInfo/distributionAdjust")
public class DistributionAdjustController extends BaseController
{
    private String prefix = "agentInfo/distributionAdjust";

    @Autowired
    private IDistributionAdjustService distributionAdjustService;

    @RequiresPermissions("agentInfo:distributionAdjust:view")
    @GetMapping()
    public String distributionAdjust()
    {
        return prefix + "/distributionAdjust";
    }

    /**
     * 查询服务商分润调整项列表
     */
    @RequiresPermissions("agentInfo:distributionAdjust:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DistributionAdjust distributionAdjust)
    {
        startPage();
        List<DistributionAdjust> list = distributionAdjustService.selectDistributionAdjustList(distributionAdjust);
        return getDataTable(list);
    }

    /**
     * 导出服务商分润调整项列表
     */
    @RequiresPermissions("agentInfo:distributionAdjust:export")
    @Log(title = "服务商分润调整项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DistributionAdjust distributionAdjust)
    {
        List<DistributionAdjust> list = distributionAdjustService.selectDistributionAdjustList(distributionAdjust);
        ExcelUtil<DistributionAdjust> util = new ExcelUtil<DistributionAdjust>(DistributionAdjust.class);
        return util.exportExcel(list, "distributionAdjust");
    }

    /**
     * 新增服务商分润调整项
     */
    @GetMapping("/upload")
    public String upload()
    {
        return prefix + "/upload";
    }

    /**
     * 新增保存服务商分润调整项
     */
    @RequiresPermissions("agentInfo:distributionAdjust:upload")
    @Log(title = "服务商分润调整项", businessType = BusinessType.INSERT)
    @PostMapping("/upload")
    @ResponseBody
    public AjaxResult uploadSave(MultipartFile file)
    {
        return toAjax(distributionAdjustService.uploadDistributionAdjust(file, this.getLoginName()));
    }

    /**
     * 删除服务商分润调整项
     */
    @RequiresPermissions("agentInfo:distributionAdjust:examine")
    @Log(title = "服务商分润调整项", businessType = BusinessType.UPDATE)
    @PostMapping( "/examine")
    @ResponseBody
    public AjaxResult examine(DistributionAdjust distributionAdjust)
    {
        distributionAdjust.setExamineMan(this.getLoginName());
        distributionAdjust.setExamineTime(DateUtils.getDateTime());
        return toAjax(distributionAdjustService.examine(distributionAdjust));
    }
}
